package com.jvtd.eyl.widget.adapter;

import android.databinding.ViewDataBinding;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.jvtd.eyl.BR;
import com.jvtd.eyl.R;
import com.jvtd.eyl.bean.binding.BookBean;
import com.jvtd.utils.UiUtils;
import com.jvtd.widget.adapter.JvtdQuickAdapter;
import com.jvtd.widget.adapter.viewHolder.JvtdViewHolder;
import com.jvtd.widget.imageView.JvtdRcImageView;
import com.sxu.shadowdrawable.ShadowDrawable;

import java.util.ArrayList;
import java.util.List;

/**
 * 书籍列表条目
 *
 * 作者:chenlei
 * 时间:2018/11/14 9:34 AM
 */
public class BookAdapter extends JvtdQuickAdapter<BookBean,JvtdViewHolder> {
    private boolean isSelected = false;//是否选择模式

    public BookAdapter() {
        super(R.layout.adapter_book, new ArrayList<>());
    }

    @Override
    protected void convert(JvtdViewHolder helper, BookBean item) {
        int index = getData().indexOf(item);
        ViewDataBinding binding = helper.getBinding();
        binding.setVariable(BR.itemBean, item);
        binding.setVariable(BR.selected, isSelected);
        binding.executePendingBindings();

//        ImageView imageView = helper.getView(R.id.book_img);
//        FrameLayout frameLayout = helper.getView(R.id.book_img_bg);
//        ShadowDrawable.setShadowDrawable(frameLayout,UiUtils.dp2px(mContext,5), ContextCompat.getColor(mContext,R.color.color_shadow), UiUtils.dp2px(mContext,4), 0, 0);
//        int itemWidth = Math.min(UiUtils.windowWidth(mContext)/3 - UiUtils.dp2px(mContext, 10) * 2, UiUtils.dp2px(mContext, 96.0f));
//        UiUtils.setAutoHeight(imageView,itemWidth,96.f / 132.f);

        helper.addOnClickListener(R.id.add_btn)
                .addOnClickListener(R.id.show_btn)
                .addOnLongClickListener(R.id.show_btn)
                .addOnClickListener(R.id.check_box);
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }
}
